<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.Map" %>
<%
    int productId = Integer.parseInt(request.getParameter("productId"));
    int quantity = Integer.parseInt(request.getParameter("quantity"));

    Map<Integer, Map<String, Object>> cart = (Map<Integer, Map<String, Object>>)session.getAttribute("cart");
    if(cart != null && cart.containsKey(productId)) {
        if(quantity > 0) {
            cart.get(productId).put("quantity", quantity);
        } else {
            cart.remove(productId);
        }
    }

    response.sendRedirect("cart.jsp");
%>